<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>别名 mysqli::__construct</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysqli-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqli_connect</h1>
  <p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">mysqli_connect</span> &mdash; <span class="dc-title">别名 <span class="methodname"><a href="mysqli.construct.html" class="methodname">mysqli::__construct()</a></span></span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.mysqli-connect-description">
  <h3 class="title">说明</h3>
  <p class="para">
   此函数是该函数的别名： <span class="methodname"><a href="mysqli.construct.html" class="methodname">mysqli::__construct()</a></span>
  </p>
  <p class="para">
   虽然说在 <span class="methodname"><a href="mysqli.construct.html" class="methodname">mysqli::__construct()</a></span> 的文档
   对 <span class="function"><strong>mysqli_connect()</strong></span> 函数也进行了详细的说明，
   这里依然给出一个简单的示例：
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysqli-connect-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1919">
   <p><strong>Example #1 <span class="function"><strong>mysqli_connect()</strong></span> 例程</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_db"</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Error:&nbsp;Unable&nbsp;to&nbsp;connect&nbsp;to&nbsp;MySQL."&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Debugging&nbsp;errno:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysqli_connect_errno</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Debugging&nbsp;error:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysqli_connect_error</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Success:&nbsp;A&nbsp;proper&nbsp;connection&nbsp;to&nbsp;MySQL&nbsp;was&nbsp;made!&nbsp;The&nbsp;my_db&nbsp;database&nbsp;is&nbsp;great."&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">"Host&nbsp;information:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysqli_get_host_info</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">mysqli_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Success: A proper connection to MySQL was made! The my_db database is great.
Host information: localhost via TCP/IP
</pre></div>
   </div>
  </div>
 </div>

</div></div></div></body></html>